package com.faf.tools;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PHOUtils {
	public static boolean checkNickName(String nickName) {
		   // 过滤出纯数字
		   nickName = Pattern.compile("[^0-9]").matcher(nickName.trim()).replaceAll("");
		   if (nickName.length() < 11) {
		      return true;
		   }
		   char[] chars = nickName.toCharArray();
		   ArrayList<String> phoneList = new ArrayList<>();//所有11位数字的集合
		   for(int i = 0; i < chars.length; i++){
		      StringBuilder stringBuilder = new StringBuilder();
		      for(int j = 0; j < 11; j++){
		         if(i + j < chars.length){
		            stringBuilder.append(chars[i + j]);
		         }
		      }
		      if(stringBuilder.length()==11){
		         phoneList.add(stringBuilder.toString());
		      }
		   }

		   List<String> regexList = new ArrayList<String>();
		   /**
		    * 手机号码
		    * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
		    * 联通：130,131,132,152,155,156,185,186
		    * 电信：133,1349,153,180,189,181(增加)
		    */
		   regexList.add("^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$");
		   /**
		    * 中国移动：China Mobile
		    * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
		    */
		   regexList.add("^1(34[0-8]|(3[5-9]|5[017-9]|8[2378])\\d)\\d{7}$");
		   /**
		    * 中国联通：China Unicom
		    * 130,131,132,152,155,156,185,186
		    */
		   regexList.add("^1(3[0-2]|5[256]|8[56])\\d{8}$");
		   /**
		    * 中国电信：China Telecom
		    * 133,1349,153,180,189,181(增加)
		    */
		   regexList.add("^1((33|53|8[019])[0-9]|349)\\d{7}$");
		   for(String phone : phoneList){
		      for (String regex : regexList) {
		         Pattern pattern = Pattern.compile(regex);
		         Matcher matcher = pattern.matcher(phone);
		         if (matcher.matches()) {
		            return false;
		         }
		      }
		   }



		   return true;
		}
	
}
